package wiki.hitime.stl.daq.web.controller.admin;

import wiki.hitime.stl.daq.bean.base.RespDTO;
import wiki.hitime.stl.daq.bean.dto.req.ExecuteTaskRecordListReqDTO;
import wiki.hitime.stl.daq.service.admin.RecordManageService;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author zhangdaoping
 * @create 2019-07-31 14:32
 */
@RestController
@RequestMapping("/admin/record")
public class RecordManageController {

    private RecordManageService recordManageService;

    public RecordManageController(RecordManageService recordManageService) {
        this.recordManageService = recordManageService;
    }

    /**
     * 获取执行记录
     *
     * @param reqDTO
     * @param bindingResult
     * @return
     */
    @PostMapping("/list")
    public RespDTO listRecord(@Valid @RequestBody ExecuteTaskRecordListReqDTO reqDTO, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return RespDTO.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return RespDTO.success(recordManageService.listRecord(reqDTO));
    }
}
